package com.haitaoit.chengquan.module.home.activity.maintenance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.module.home.model.MaintenanceServerModel;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/10/24.
 */
public class MaintenanceServerAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List<MaintenanceServerModel> list;

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public MaintenanceServerAdapter(Context context) {
        this.context = context;
    }

    public List<MaintenanceServerModel> getList() {
        return list;
    }

    public void setList(List<MaintenanceServerModel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.maintenance_server_item, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ImageLoader.getInstance().displayImage(list.get(position).getTitle_img(), holder.title_img);
        holder.title.setText(list.get(position).getTitle());
        holder.describe.setText(list.get(position).getDescribe());
        if (list.get(position).getType().equals("7")) {
            holder.reference_price.setText("¥ " + list.get(position).getReference_price_low() + "～¥ " + list.get(position).getReference_price_high());
        } else {
            holder.reference_price.setText("¥ " + list.get(position).getReference_price_low());
        }
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.title_img)
        ImageView title_img;
        @ViewInject(R.id.title)
        TextView title;
        @ViewInject(R.id.describe)
        TextView describe;
        @ViewInject(R.id.reference_price)
        TextView reference_price;
    }
}
